<?php

namespace App\Admin\Controllers;

use App\Miya\Models\Blogroll;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class BlogrollController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '友情链接';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Blogroll());

        $grid->column('id', '序号');
        $grid->column('name', '名称');
        $grid->column('avatar', 'Logo')->light_box(['height' => 18]);
        $grid->column('url', '链接')->link();
        $grid->column('rank', '排序')->editable()->sortable();

        return $grid;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Blogroll());

        $form->text('name', '名称')->rules(['required']);
        $form->image('avatar', 'Logo')->uniqueName()->removable()->move(getMovePath('blogrolls'));
        $form->url('url', '链接');
        $form->slider('rank', '排序')->default(1)->options([
            'max' => 100,
            'min' => 1,
            'step' => 1,
        ]);

        return $form;
    }
}
